package core.toolbox.Period;

import com.jfinal.plugin.activerecord.Db;
import core.shiro.ShiroUtils;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/3/15.
 */
public class PeriodUtils {
    private static Integer currentPeriod = null;

    public static int getCurrentPeriod(){
        if(currentPeriod == null)
            currentPeriod = Db.queryInt("select account_period from account_period_current");
        return currentPeriod;
    }

    public static List<Map> getSelectPeriod(int start, int end){
        List<Map> list = new LinkedList();
        for(int i =1;i <= getCurrentPeriod(); i++){
            Map map = new HashMap();
            map.put("data","2017年第"+i+"期");
            if(i == start){
                map.put("selected", 1);
            }
            if(i == end){
                map.put("selected", 2);
            }
            if(start==end && i==start){
                map.put("selected", 3);
            }
            if(i != start && i != end){
                map.put("selected", 0);
            }

            list.add(map);
        }

        return list;
    }


    public static void nextPeriod(){
        Db.update("call nextPeriod(?)", ShiroUtils.getUserId());
    }


}
